import router from '@system.router';
import swiperData from '../../../common/swiperdata.js'
//调用天气api需要获得响应网络权限
import http from '@ohos.net.http'
export default {
    data() {
        return {
            swiperdata:swiperData,
            tem:'',
            temh:'',
            condition:'',
            warn:'',
            aircondition:'',
            tips:''
        }
    },
    onInit() {
        // 每一个httpRequest对应一个http请求任务，不可复用
        //        请求天气信息
        let httpRequest= http.createHttp();
        httpRequest.request("https://v0.yiketianqi.com/api?unescape=1&version=v61&appid=49799419&appsecret=o3baViIp&city=桂林",
            {
                method: 'GET',
                header: {
                    'Content-Type': 'application/json'
                },
                readTimeout: 60000,
                connectTimeout: 60000
            },(err, data) => {
                if (!err) {
                    console.info('Result:' + data.result);
                    this.dataweather=JSON.parse(data.result);
                    this.tem=this.dataweather.tem+"℃";
                    this.temh=this.dataweather.tem1+"℃"+"/"+this.dataweather.tem2+"℃";
                    this.condition=this.dataweather.wea+"   "+this.dataweather.win+this.dataweather.win_speed
                    this.warn=this.dataweather.alarm.alarm_type+this.dataweather.alarm.alarm_level+"预警 >",
                    this.aircondition="空气质量        "+this.dataweather.aqi.air_level
                    this.tips=this.dataweather.aqi.air_tips
                    console.info('code:' + this.dataweather.date);
                    console.info('header:' + this.dataweather.week);
                } else {
                    console.info('error:' + err.data);
                }
            });

    },
//    跳转警报详情
    warncontent(){
        router.push({
            uri: 'pages/homepage/warning/warning',
        });
    }
}
